package mn.more.foundation.collections;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

/**
 * @author <a href="mailto:mike.liu@aptechmongolia.edu.mn">Mike Liu</a>
 * @version $Id: CollectionUtil.java 5 2008-09-01 12:08:42Z mikeliucc $
 */
public final class CollectionUtil {

	/** singleton constr. */
	private CollectionUtil() { }

	/**
	 * add all the items in <code>data</code> sequentially to
	 * <code>collection</code>.
	 *
	 * @param collection the target collection
	 * @param data       the array of data to add
	 */
	public static void addTo(Collection<Object> collection, Object[] data) {
		// sanity check
		if (collection == null) { return; }
		if (data == null || data.length < 1) { return; }
		collection.addAll(Arrays.asList(data));
	}

	/**
	 * verify that <code>collections</code> is not null and contains at least one
	 * element.
	 *
	 * @return true if <code>collections</code> is null and contains no element.
	 */
	public static boolean isEmpty(Collection collection) {
		return collection == null || collection.size() < 1;
	}

	/**
	 * verify that <code>list</code> is not null and contains at least one
	 * element.
	 *
	 * @return true if <code>list</code> is null and contains no element.
	 */
	public static boolean isEmpty(Map map) {
		return map == null || map.size() < 1;
	}
}
